﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using EntLibEC.Cmn;
using EntLibEC.Biz;
using EntLibEC.Biz.Basic;
using EntLibEC.Info.Basic;

namespace EntLibEC.Shopping.Include
{
    public partial class AreaDropDown : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        /// <summary>
        /// 获取当前地区中的省编号
        /// </summary>
        public int ProvinceSysNo
        {
            get
            {
                if (ddlProvince.SelectedValue.Trim().Length == 0)
                    return AppConst.IntNull;
                else
                    return Convert.ToInt32(ddlProvince.SelectedItem.Value);
            }
        }
        /// <summary>
        /// 获取当前地区中的市编号
        /// </summary>
        public int CitySysNo
        {
            get
            {
                if (ddlCity.SelectedValue.Trim().Length == 0)
                    return AppConst.IntNull;
                else
                    return Convert.ToInt32(ddlCity.SelectedItem.Value);
            }
        }
        /// <summary>
        /// 获取当前地区中的区县编号
        /// </summary>
        public int DistrictSysNo
        {
            get
            {
                if (ddlDistrict.SelectedValue.Trim().Length == 0)
                    return AppConst.IntNull;
                else
                    return Convert.ToInt32(ddlDistrict.SelectedItem.Value);
            }
        }
        /// <summary>
        /// 获取当前地区最底层的编号，区县不为空返回区县，区县为空看市区，市区为空看省，都为空返回系统的空。
        /// </summary>
        public int AreaSysNo
        {
            get
            {
                if (this.DistrictSysNo != AppConst.IntNull)
                    return this.DistrictSysNo;
                else if (this.CitySysNo != AppConst.IntNull)
                    return this.CitySysNo;
                else if (this.ProvinceSysNo != AppConst.IntNull)
                    return this.ProvinceSysNo;
                else
                    return AppConst.IntNull;
            }
            set
            {
                AreaInfo oParam = ASPManager.GetInstance().GetAreaHash()[value] as AreaInfo;
                if (oParam != null)
                {
                    switch (ASPManager.GetInstance().GetAreaType(oParam))
                    {
                        case (int)AppEnum.AreaType.District:
                            //ddlProvince.SelectedIndex = ddlProvince.Items.IndexOf(ddlProvince.Items.FindByValue(oParam.ProvinceSysNo.ToString()));
                            //ddlCity.SelectedIndex = ddlCity.Items.IndexOf(ddlCity.Items.FindByValue(oParam.CitySysNo.ToString()));
                            //ddlDistrict.SelectedIndex = ddlDistrict.Items.IndexOf(ddlDistrict.Items.FindByValue(oParam.SysNo.ToString()));
                            cddProvince.SelectedValue = oParam.ProvinceSysNo.ToString();
                            cddCity.SelectedValue = oParam.CitySysNo.ToString();
                            cddDistrict.SelectedValue = oParam.SysNo.ToString();
                            break;
                        case (int)AppEnum.AreaType.City:
                            //ddlProvince.SelectedIndex = ddlProvince.Items.IndexOf(ddlProvince.Items.FindByValue(oParam.ProvinceSysNo.ToString()));
                            //ddlCity.SelectedIndex = ddlCity.Items.IndexOf(ddlCity.Items.FindByValue(oParam.SysNo.ToString()));
                            cddProvince.SelectedValue = oParam.ProvinceSysNo.ToString();
                            cddCity.SelectedValue = oParam.SysNo.ToString();
                            break;
                        case (int)AppEnum.AreaType.Province:
                            //ddlProvince.SelectedIndex = ddlProvince.Items.IndexOf(ddlProvince.Items.FindByValue(oParam.SysNo.ToString()));
                            cddProvince.SelectedValue = oParam.SysNo.ToString();
                            break;
                        default:
                            break;
                    }
                }
            }
        }
    }
}